package com.线程Thread;

public class Runnable01 {
    public static void main(String[] args) throws InterruptedException {
        Monkey monkey = new Monkey();
//        m.start();  Runnable接口没有start方法，只能通过以下方式创建线程；
        Thread thread = new Thread(monkey);  // 静态代理设计模式
        thread.start();  //创建线程，调用Monkey的run方法

        for (int i = 0; i < 5; i++) {
            System.out.println("main"+i+"  -- main线程的名字为"+Thread.currentThread().getName());
            Thread.sleep(1000);
        }
        System.out.println("main线程结束");
    }
}

class Monkey implements Runnable {

    @Override
    public void run() {
        int count = 0;
        while(count != 8){
            count++;
            System.out.println("Monkey"+count+"  --  线程的名字为"+Thread.currentThread().getName());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        System.out.println("Monkey线程结束");
    }
}